package com.hopu.v1.controller.admin.subject;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.system.Class;
import com.hopu.v1.pojo.system.StaffSubject;
import com.hopu.v1.service.admin.subject.ClassService;
import com.hopu.v1.vo.ClassVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/v1/class")
public class ClassController {

    @Resource
    private ClassService classService;

    /**
     * 获取班级列表
     * @return
     */
    @GetMapping("/getClassList")
    public R selectAll(Page<Class> page, String className, String realName, String teacherName, String subjectName,Integer classStatus,Integer staffId){
        //System.out.println(class1);
        PageData<StaffSubject> pageData = classService.selectAll(page,className,realName,teacherName,subjectName,classStatus,staffId);
        return R.ok("获取成功",pageData);
    }

    /**
     * 添加班级
     */
    @PostMapping("/insert")
    public R insert(Class class1) {
        //System.out.println(class1);
        class1.setStartDate(LocalDate.now());
        class1.setClassStatus(1);
        this.classService.insert(class1);
        return R.ok("添加成功");
    }

    /**
     * 修改班级
     */
    @PutMapping("/update")
    public R update(@RequestBody Class class1,String className) {
        //System.out.println(class1);
        //this.classService.updateById(class1);
        classService.update(class1,className);
        return R.ok("修改成功");
    }

    /**
     * 删除班级
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam("id") int id) {
        return R.ok("删除成功",classService.removeById(id));
    }

    /**
     * 根据id获取班级内学生人数
     */
    @GetMapping("/getClassNumbers")
    public R getNumberById(@RequestParam(value = "id",required = false) Integer classId){
        Integer number = this.classService.getNumberById(classId);
        //System.out.println(number);
        return R.ok(number);
    }

    /**
     * 修改状态创建结业的时间
     * @param id
     * @return
     */
    @PostMapping("updateClassStatus")
    public R updateClassStatus(Integer id, Integer classStatus,LocalDate endDate) {
        classService.updateClassStatus(id,classStatus,endDate);
        return R.ok("修改状态成功！");
    }

    /**
     * 根据班级id查询班级信息
     * @param classId
     * @return
     */
    @GetMapping("getClassInfo")
    public R getClassInfo(Integer classId) {
        return R.ok(classService.getClassInfo(classId));
    }}
